Skip to content

[lldb] Refactor helper by using iterators and in-place edits (NFC) #116876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

adrian-prantl
Copy link
Collaborator

Based on post-commit review feedback by Felipe Piovezan!

Based on post-commit review feedback by Felipe Piovezan!
@llvmbot
Copy link
Member

llvmbot commented Nov 19, 2024

@llvm/pr-subscribers-lldb

Author: Adrian Prantl (adrian-prantl)

Changes

Based on post-commit review feedback by Felipe Piovezan!


Full diff: https://github.com/llvm/llvm-project/pull/116876.diff

1 Files Affected:

  • (modified) lldb/source/Utility/DiagnosticsRendering.cpp (+8-15)
diff --git a/lldb/source/Utility/DiagnosticsRendering.cpp b/lldb/source/Utility/DiagnosticsRendering.cpp
index a20d82ad4eb678..f5aa27baadfef8 100644
--- a/lldb/source/Utility/DiagnosticsRendering.cpp
+++ b/lldb/source/Utility/DiagnosticsRendering.cpp
@@ -132,23 +132,16 @@ void RenderDiagnosticDetails(Stream &stream,
   stream << '\n';
 
   // Reverse the order within groups of diagnostics that are on the same column.
-  auto group = [](const std::vector<DiagnosticDetail> &details) {
-    uint16_t column = 0;
-    std::vector<DiagnosticDetail> result, group;
-    for (auto &d : details) {
-      if (d.source_location->column == column) {
-        group.push_back(d);
-        continue;
-      }
-      result.insert(result.end(), group.rbegin(), group.rend());
-      group.clear();
-      column = d.source_location->column;
-      group.push_back(d);
+  auto group = [](std::vector<DiagnosticDetail> &details) {
+    for (auto it = details.begin(), end = details.end(); it != end;) {
+      auto eq_end = std::find_if(it, end, [&](const DiagnosticDetail &d) {
+        return d.source_location->column != it->source_location->column;
+      });
+      std::reverse(it, eq_end);
+      it = eq_end;
     }
-    result.insert(result.end(), group.rbegin(), group.rend());
-    return result;
   };
-  remaining_details = group(remaining_details);
+  group(remaining_details);
 
   // Work through each detail in reverse order using the vector/stack.
   bool did_print = false;

Copy link
Contributor

@felipepiovezan felipepiovezan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is even better than the original suggestion!

@adrian-prantl adrian-prantl merged commit 174899f into llvm:main Nov 19, 2024
7 of 8 checks passed
adrian-prantl added a commit to adrian-prantl/llvm-project that referenced this pull request Nov 19, 2024
…lvm#116876)

Based on post-commit review feedback by Felipe Piovezan!

(cherry picked from commit 174899f)
adrian-prantl added a commit to adrian-prantl/llvm-project that referenced this pull request Dec 5, 2024
…lvm#116876)

Based on post-commit review feedback by Felipe Piovezan!

(cherry picked from commit 174899f)
(cherry picked from commit a4b1912)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants